import axios from 'axios';
import _ from 'lodash';
let apiHostName = window.location.hostname;
let LocationHostName = window.location.hostname;
if (LocationHostName === 'localhost' || LocationHostName === '127.0.0.1') {
    apiHostName = '/api';
    LocationHostName = '/host';
}
let API = {
    API_SERVER_URL:apiHostName,
    HOST_SERVER_URL:LocationHostName,
    LOGIN: '/api/User/login', //登录接口
    LOGOUT: '/api/User/Logout', //退出登录
    USERS: '/api/User', //用户登录
    WORK_CALALOG: '/api/Catalog/tree', //获取树形结构
    WORK_CALALOG_BATH: '/api/Catalog', //树形结构curd
    WORK_TASK: '/api/Task', //作业curd
    WORK_PART:'/api/TaskPart',//零部件curd
    COMMON_FILE_UPLOAD:'/api/File/upload',//文件上传
    HOST_FILE_UPLOAD:'/Host/UploadPart',//文件上传
    MATERIA:'/api/Material',
    ORGANIZATION:'/api/Organization',
    GET_WAREHOUSE:'/api/Warehouse',
    SET_USER_WARES:'/api/User/wares',//保存用户与仓库的关系 
    SET_USER_ORG:'/api/User/org',//保存用户和组织关系
    GET_USER_WARE:'/api/Warehouse/user-ware',//获取用户的仓库
    GET_USER_STOCK:'/api/Stock',//获取用户仓库库存
    SET_LAYOUT_UNLOCK:'/api/Layout/unlock',//解锁排样零件数量
    SET_LAYOUT_LOCK:'/api/Layout/lock',//锁定排样零件数量
    GET_LAYOUT:'/api/Layout',//排样数据
    PUT_PRODUCTION:'/api/Layout/production',//排产
    PUT_PRODUCTION_FACUT:'/api/Layout/productionFACut',//FACut#
    PRODUCTION:'/api/Layout',//删除排样结果
    MACHINE:'/api/Machine',//设备
    SYNCHRONOUS:"api/Task/sync",//同步
};

export function getConfig(){
    return new Promise(resolve=>{
        axios.get(`${window.location.origin}/webconfig.json?v=${new Date().getTime()}`).then((response) => {
            if (response.data && _.isPlainObject(response.data)) {
                if(process.env.NODE_ENV === 'development'){
                    delete response.data.API_SERVER_URL;
                    delete response.data.HOST_SERVER_URL;
                }
                resolve(Object.assign({},API, response.data))
            }else{
                resolve(API)
            }
        }, () => {
            resolve(API)
        });
    })
}
export default API;


